// pages/setting/blackList.js
const httpUtils = require('../../utils/httpUtils')
const ui = require('../../utils/ui')

Page({
  data: {
    page: 1,
    cells: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.requestList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.setData({
      page: 1
    });
    this.requestList();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.setData({
      page: this.data.page + 1
    });
    this.requestList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  //取消黑名单
  actionCancelBlack(event) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确定要将该用户从黑名单去除？',
      complete: (res) => {
        if (res.confirm) {
          let obj = {
            method: 'DELETE',
            contentType: 'application/x-www-form-urlencoded',
            url: '/user/black-list/'+event.currentTarget.dataset.id,
            showLoading: true,
            data: {}
          }
          httpUtils.request(obj).then(res => {
            ui.showToast("取消成功");
            that.requestList();
          }).catch(err => {
            console.log('ERROR')
          });
        }
      }
    });
  },
  //请求列表
requestList() {
  let obj = {
    method: 'GET',
    url: '/user/black-list',
    showLoading: true,
    data: {
      page: this.data.page,
      size: 20
    }
  }
  httpUtils.request(obj).then(res => {
    if (this.data.page == 1) {
      this.setData({
        cells: []
      });
    }
    const {
      cells = []
    } = this.data;
    res.data.blackListDetailDtos.forEach(function (item, index) {
      cells.push(item);
    });
    this.setData({
      cells
    });
    
  }).catch(err => {
    console.log(err)
  });
}
})